package com.cssw.fyzb.wap.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.dto.*;
import com.cssw.fyzb.wap.model.vo.*;
import com.cssw.fyzb.wap.service.AnchorService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wondream
 */
@RestController
@RequestMapping("/anchor")
public class AnchorController {

    @Autowired
    AnchorService anchorService;

    @ApiOperation(value = "根据主播id获取主播信息")
    @ApiImplicitParam(name = "anchorId", value = "主播id", paramType = "query", dataType = "Long", required = true)
    @GetMapping("queryAnchorById")
    @ResponseBody
    public AjaxData<AnchorVo> queryAnchorById(Long anchorId) {
        return anchorService.queryAnchorById(anchorId);
    }

    @ApiOperation(value = "通过用户id获取主播信息")
    @GetMapping("queryAnchorByUserId")
    @ResponseBody
    public AjaxData<AnchorVo> queryAnchorByUserId() {
        return anchorService.queryAnchorByUserId(UserContext.getUserId());
    }


    @ApiOperation("加入黑名单")
    @ApiImplicitParam(name = "dto", value = "加入黑名单", dataType = "AddAnchorBlacklistDto")
    @PostMapping("addAnchorBlacklist")
    @ResponseBody
    public AjaxData addAnchorBlacklist(@RequestBody AddAnchorBlacklistDto dto) {
        return anchorService.addAnchorBlacklist(dto.getAnchorId(), dto.getUserId());
    }

    @ApiOperation("增加管理员")
    @ApiImplicitParam(name = "dto", value = "增加管理员", dataType = "AddAnchorBlacklistDto")
    @PostMapping("addAnchorManage")
    @ResponseBody
    public AjaxData addAnchorManage(@RequestBody AddAnchorManageDto dto) {
        return anchorService.addAnchorManage(dto.getAnchorId(), dto.getUserId());
    }

    @ApiOperation("增加敏感词")
    @ApiImplicitParam(name = "dto", value = "增加敏感词", dataType = "AddAnchorSensitiveDto")
    @PostMapping("addAnchorSensitive")
    @ResponseBody
    public AjaxData addAnchorSensitive(@RequestBody AddAnchorSensitiveDto dto) {
        return anchorService.addAnchorSensitive(dto.getAnchorId(), dto.getKeyWord());
    }

    @ApiOperation("删除黑名单")
    @ApiImplicitParam(name = "dto", value = "删除黑名单", dataType = "DeleteByIdDto")
    @PostMapping("removeAnchorBlacklist")
    @ResponseBody
    public AjaxData removeAnchorBlacklist(@RequestBody DeleteByIdDto dto) {
        return anchorService.removeAnchorBlacklist(dto.getId());
    }

    @ApiOperation("删除管理员")
    @ApiImplicitParam(name = "dto", value = "删除管理员", dataType = "DeleteByIdDto")
    @PostMapping("removeAnchorManage")
    @ResponseBody
    public AjaxData removeAnchorManage(@RequestBody DeleteByIdDto dto) {
        return anchorService.removeAnchorManage(dto.getId());
    }

    @ApiOperation("删除敏感词")
    @ApiImplicitParam(name = "dto", value = "删除敏感词", dataType = "DeleteByIdDto")
    @PostMapping("removeAnchorSensitive")
    @ResponseBody
    public AjaxData removeAnchorSensitive(@RequestBody DeleteByIdDto dto) {
        return anchorService.removeAnchorSensitive(dto.getId());
    }

    @ApiOperation("获取黑名单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "anchorId", value = "主播标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("listAnchorBlacklist")
    @ResponseBody
    public AjaxPage<LiveKickOutVo> listAnchorBlacklist(int pageNumber, int pageSize, Long anchorId) {
        return anchorService.listAnchorBlacklist(anchorId, pageNumber, pageSize);
    }

    @ApiOperation("获取管理员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "anchorId", value = "主播标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("listAnchorManage")
    @ResponseBody
    public AjaxPage<AnchorManageVo> listAnchorManage(int pageNumber, int pageSize, Long anchorId) {
        return anchorService.listAnchorManage(anchorId, pageNumber, pageSize);
    }

    @ApiOperation("获取敏感词列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "anchorId", value = "主播标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("listAnchorSensitive")
    @ResponseBody
    public AjaxPage<AnchorSensitiveVo> listAnchorSensitive(int pageNumber, int pageSize, Long anchorId)  {
        return anchorService.listAnchorSensitive(anchorId, pageNumber, pageSize);
    }

    @ApiOperation("验证直播条件")
    @GetMapping("liveVerification")
    @ResponseBody
    public AjaxPage liveVerification() {
        return anchorService.liveVerification(UserContext.getUserId());
    }

    @ApiOperation("开通直播权限")
    @PostMapping("openAnchor")
    @ResponseBody
    public AjaxData openAnchor() {
        return anchorService.openAnchor(UserContext.getUserId());
    }

    @ApiOperation("开通VIP直播权限")
    @ApiImplicitParam(name = "dto", value = "开通VIP直播权限", dataType = "OpenVipAnchorDto")
    @PostMapping("openVipAnchor")
    @ResponseBody
    public AjaxData openVipAnchor(@RequestBody OpenVipAnchorDto dto) {
        return anchorService.openVipAnchor(UserContext.getUserId(), dto.getTradePwd());
    }

    @ApiOperation("修改直播间标题")
    @ApiImplicitParam(name = "dto", value = "获取管理员列表", dataType = "UpdateTitleDto")
    @PostMapping("updateTitle")
    @ResponseBody
    public AjaxData updateTitle(@RequestBody UpdateTitleDto dto) {
        return anchorService.updateTitle(dto.getAnchorId(), dto.getTitle());
    }

    @ApiOperation("修改直播间封面")
    @ApiImplicitParam(name = "dto", value = "获取管理员列表", dataType = "UpdateThumbDto")
    @PostMapping("updateThumb")
    @ResponseBody
    public AjaxData updateTitle(@RequestBody UpdateThumbDto dto) {
        return anchorService.updateThumb(dto.getAnchorId(), dto.getThumb());
    }

}
